//
//  ByWithdrawVC.m
//  caipiao_ios
//
//  Created by mc on 2018/7/9.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByWithdrawVC.h"
#import "ByMoneyChangeDetailVC.h"
#import "ByWithdrawView.h"
#import "ByWithdrawDetailVC.h"

@interface ByWithdrawVC ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *valueLabel;

@end

@implementation ByWithdrawVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLeftBackBarButtonItem];
    self.title = @"提现";
    [self initViews];
    
    [self addBYItemviews:@[@"提现明细"] mode:ByNavigationItemModeText  position:ByNavigationItemPositionModeRight];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    [self setNaviAttributeWithTranslucent:YES stateBarLightContent:NO];
    [self loadData];
}



- (void)loadData{
    
   
    
    [ByMoneyApi userMoneyFollowSuccess:^(ByNetBaseResult *result) {
        
        NSLog(@"查询 = %@", result.data);
        NSDictionary *dic = result.data[@"data"];
        
        NSString *keyong = dic[@"keyong"];
        NSString *tixian = dic[@"tixian"];
        
        ByModelUser *user = BY_USER;
        user.withdrawals_money = tixian;
        user.user_money = keyong;
        [ByCacheUser setUserInfo:user];
        self.valueLabel.text = [NSString stringWithFormat:@"%.2f", BY_USER.user_money.floatValue];
    } failure:^(ByNetBaseResult *result) {
        
        [ByCoreToolAlert showFailureWithText:result.msg];
    }];
    
}

- (void)rightItemsAction:(NSInteger)rightIndex{
    
    ByMoneyChangeDetailVC *vc = [[ByMoneyChangeDetailVC alloc] init];
    vc.type = 2;
    [self by_normalPush:vc hasNavi:YES];
}

- (void)initViews{
    
    UIImageView *backgroudView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH *0.6)];
    backgroudView.image = [UIImage imageNamed:@"tixianbeijing"];
    [self.view addSubview:backgroudView];
  
    self.valueLabel = [[UILabel alloc] init];
    [backgroudView addSubview:self.valueLabel];
    [self.valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroudView).offset(22);
        make.right.equalTo(backgroudView).offset(-10);
        make.bottom.equalTo(backgroudView).offset(-32);
        make.height.mas_equalTo(@50);
    }];
    self.valueLabel.text = [NSString stringWithFormat:@"%.2f", BY_USER.user_money.floatValue];
    self.valueLabel.textColor = [UIColor whiteColor];
    self.valueLabel.font = B_FONT(40);
    self.valueLabel.adjustsFontSizeToFitWidth = YES;
    
    self.titleLabel = [[UILabel alloc] init];
    [backgroudView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.valueLabel.mas_left).offset(0);
        make.right.equalTo(backgroudView).offset(-10);
        make.bottom.equalTo(self.valueLabel.mas_top).offset(-20);
        make.height.mas_equalTo(@20);
    }];
    self.titleLabel.text = @"可用余额（元）";
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = FONT(13);
   
    self.view.backgroundColor = BY_BACKGROUND_COLOR;
    
    ByWithdrawView *wechatView = [[ByWithdrawView alloc] init];
    [self.view addSubview:wechatView];
    wechatView.titleLabel.text = @"提现到支付宝";
    wechatView.typeView.image = [UIImage imageNamed:@"支付宝"];
    [wechatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.top.equalTo(backgroudView.mas_bottom).offset(12);
        make.height.mas_equalTo(@50);
    }];
    wechatView.withdrawBlock = ^(){
        ByWithdrawDetailVC *vc = [[ByWithdrawDetailVC alloc] init];
        vc.type = 0;
        [self by_normalPush:vc hasNavi:YES];
    };
    
    
    ByWithdrawView *wechatView1 = [[ByWithdrawView alloc] init];
    [self.view addSubview:wechatView1];
    wechatView1.titleLabel.text = @"提现到银行卡";
    wechatView1.typeView.image = [UIImage imageNamed:@"yuebao"];
    [wechatView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.top.equalTo(wechatView.mas_bottom).offset(1);
        make.height.mas_equalTo(@50);
    }];
    wechatView1.withdrawBlock = ^(){
        ByWithdrawDetailVC *vc = [[ByWithdrawDetailVC alloc] init];
        vc.type = 1;
        [self by_normalPush:vc hasNavi:YES];
    };
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
